package mmc.resource;

import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.ARBPointSprite.*;
import static org.lwjgl.opengl.ARBPointParameters.*;

import java.awt.image.BufferedImage;

import org.lwjgl.opengl.GL11;

public class Sprite2D{
	Texture texture;
	
	public Sprite2D(String texture){
		this.texture = TextureLoader.load(texture);
	}
	
	public Sprite2D(String name, BufferedImage img){
		this.texture = TextureLoader.load(name, img);
	}
	
	public void draw2f(float x, float y, float width, float height){
		glEnable(GL_TEXTURE_2D);
		texture.bind();
		
		float x2 = x + width;
		float y2 = y + height;
		
		GL11.glBegin(GL11.GL_QUADS); // Start Drawing Quads
		glTexCoord2f(0, 0);
		GL11.glVertex2f(x, y); // Point 1 (Front)
		glTexCoord2f(1, 0);
		GL11.glVertex2f(x2, y); // Point 2 (Front)
		glTexCoord2f(1, 1);
		GL11.glVertex2f(x2, y2); // Point 3 (Front)
		glTexCoord2f(0, 1);
		GL11.glVertex2f(x, y2); // Point 4 (Front)
		GL11.glEnd(); // Done Drawing Quads
		glDisable(GL_TEXTURE_2D);
	}
	
	public static void glSprite2D2f(String texture, float x, float y, float width, float height){
		Texture tex = TextureLoader.load(texture);
		
		glEnable(GL_TEXTURE_2D);
		tex.bind();
		
		float x2 = x + width;
		float y2 = y + height;
		
		GL11.glBegin(GL11.GL_QUADS); // Start Drawing Quads
		glTexCoord2f(0, 0);
		GL11.glVertex2f(x, y); // Point 1 (Front)
		glTexCoord2f(1, 0);
		GL11.glVertex2f(x2, y); // Point 2 (Front)
		glTexCoord2f(1, 1);
		GL11.glVertex2f(x2, y2); // Point 3 (Front)
		glTexCoord2f(0, 1);
		GL11.glVertex2f(x, y2); // Point 4 (Front)
		GL11.glEnd(); // Done Drawing Quads
		glDisable(GL_TEXTURE_2D);
	}
	
	public static void glSprite3D2f(String texture, float x, float y, float z, float size){
		glDisable(GL_LIGHTING);
		
		glPointParameterfARB(GL_POINT_SIZE_MIN_ARB, size);
        glPointParameterfARB(GL_POINT_SIZE_MAX_ARB, size);
        glPointSize(size);
        glEnable(GL_POINT_SPRITE_ARB);
        
        TextureLoader.load(texture).bind();
        
        glBegin(GL_POINTS);
        glTexCoord2f(0.5f, 0.5f);
        glVertex3f(x,y,z);
        glEnd();
        
        glDisable(GL_POINT_SPRITE_ARB);
        glEnable(GL_LIGHTING);
	}
}
